<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>任务调度页</title>
    <meta name="author" content="师师2020" />
    <link rel="stylesheet" th:href="@{/iview/iview.css}">
    <script th:src="@{/libs/jquery-3.2.1.min.js}" type="text/javascript"></script>
	<script th:src="@{/libs/vue.min.js}" type="text/javascript"></script>
	<script th:src="@{/layer/layer.js}" type="text/javascript"></script>
	<script th:src="@{/iview/iview.min.js}" type="text/javascript"></script>
    <style type="text/css">
	[v-cloak] {
			  display: none;
			}
	</style>
</head>
<body>
<div id="app" v-cloak style="margin: 30px">
<template>
	    <i-form v-ref:form-quartz :model="formQuartz" :rules="ruleValidate" :label-width="80">
	        <Form-item label="任务名称" prop="jobname">
	            <i-input  v-model="formQuartz.jobname"  :value.sync="formQuartz.jobname" placeholder="请输入任务名称"></i-input>
	        </Form-item>
	        <Form-item label="任务分组" prop="jobgroup" >
	            <i-input  v-model="formQuartz.jobgroup" :value.sync="formQuartz.jobgroup" placeholder="请输入任务分组"></i-input>
	        </Form-item>
	        <Form-item label="任务描述" prop="description">
	            <i-input  v-model="formQuartz.description" :value.sync="formQuartz.description" placeholder="请输入任务描述"></i-input>
	        </Form-item>
	        <Form-item label="执行类" prop="jobclassname">
				<i-input v-model="formQuartz.jobclassname" :value.sync="formQuartz.jobclassname" disabled="disabled" placeholder="执行类"></i-input>
	        </Form-item>
            <Form-item label="执行方法" prop="jobmethodname">
                <i-input v-model="formQuartz.jobmethodname" :value.sync="formQuartz.jobmethodname" disabled="disabled" placeholder="请输入执行类"></i-input>
            </Form-item>
	        <Form-item label="执行时间" prop="cronexpression">
	            <i-input v-model="formQuartz.cronexpression" :value.sync="formQuartz.cronexpression" placeholder="请输入任务执行时间"></i-input>
	        </Form-item>

			<Form-item label="KETTLE类型" prop="runtype">
				<i-input v-model="formQuartz.runtype" :value.sync="formQuartz.runtype" disabled="disabled" placeholder="任务类型"></i-input>
			</Form-item>
			<Form-item label="KETTLE路径" prop="kettlepatch">
				<i-input v-model="formQuartz.kettlepatch" :value.sync="formQuartz.kettlepatch" placeholder="请输入kettle文件全路径"></i-input>
			</Form-item>
			<!--<Form-item label="KETTLE参数" prop="kettledetails">
				<i-input v-model="formQuartz.kettledetails" :value.sync="formQuartz.kettledetails" placeholder="请输入JSON{KEY:VALUE,KEY:VALUE}格式路径"></i-input>
			</Form-item>-->
	    </i-form>
</template>
</div>
<script type="text/javascript">
var vm = new Vue({
	el : '#app',
	data : {
		formQuartz: {
			jobname : '',
			jobgroup : '',
			description : '',
			jobclassname : 'com.itstyle.quartz.job.kettleKtr',
			jobmethodname:'runKtr',
			cronexpression : '',
			//旧任务名称  用于修改
			oldjobname : '',
			oldjobgroup : '',
			runtype:'KTR',
			kettlepatch:'',
			kettledetails:''
        },
        ruleValidate: {
        	jobname: [
                { required: true, message: '任务名称不能为空', trigger: 'blur' }
            ],
            jobgroup: [
                { required: true, message: '任务分组不能为空', trigger: 'blur' }
            ],
            description: [
                { required: true, message: '任务描述不能为空', trigger: 'blur' }
            ],
            jobclassname: [
				{ required: true, message: '执行类不能为空', trigger: 'blur' }
			],
			jobmethodname: [
				{ required: true, message: '执行方法不能为空', trigger: 'blur' }
			],
            cronexpression: [
                { required: true, message: '执行时间不能为空', trigger: 'blur' }
            ],
			runtype: [
				{ required: true, message: '执行类型不能为空', trigger: 'blur' }
			],
			kettlepatch: [
				{ required: true, message: 'kettle文件全路径不能为空', trigger: 'blur' }
			]
        }
	},
	methods : {
		//新建任务(略简单)
		acceptClick : function(){
		  //Validate不起作用MD
		    var quartz =  vm.formQuartz;
		  if(vm.formQuartz.jobname==""||vm.formQuartz.jobgroup==""||vm.formQuartz.description==""
				  ||vm.formQuartz.jobclassname==""||vm.formQuartz.cronexpression==""||vm.formQuartz.kettlepatch==""){
			  alert("请输入以上完整信息");
			  return;
		  }
			quartz=upperJSONKey(quartz);
		  $.ajax({
				url:"../job/add",
				type:"post",
				data:quartz,
				success: function(result) {
					if(result.code=="0"){
						window.parent.location.reload();
					}else{
						vm.$Notice.error({
		                    desc: result.msg
		                });
					}
				}
			});
		}
	},
	created : function() {

	}
})


// 大写转换
function upperJSONKey(jsonObj){

	for (var key in jsonObj){
		if(allCaps(key)){

		jsonObj[key.toUpperCase()] = jsonObj[key];
		delete(jsonObj[key]);

		}

	}
	return jsonObj;
}

// 小写转换
function lowerJSONKey(jsonObj){
	for (var key in jsonObj){
		jsonObj[key.toLowerCase()] = jsonObj[key];
		delete(jsonObj[key]);
	}
	return jsonObj;
}

function allCaps(text){
	for(var i=0;i<text.length;i++){
		var c=text.charAt(i);
		if(c<'A' || c>'Z')
			return true;
	}
	return false;
}
</script>
</body>
</html>